package com.dyz.leetcode._03_mathematics;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class _989_addToArrayForm {
    public List<Integer> addToArrayForm(int[] num, int k) {
        List<Integer> res = new ArrayList<>();
        int carry = 0;
        int l1 = num.length-1;
        while(l1>=0 || k!=0){
            int x = l1<0?0:num[l1];
            int y = k==0?0:k%10;
            int sum = x+y+carry;
            res.add(sum%10);
            carry = sum/10;

            l1--;
            k=k/10;
        }
        if(carry!=0){res.add(1);}
        Collections.reverse(res);
        return res;
    }
}
